﻿<%@ page import = "java.util.*" %>		
<%@ page import="nftrainer.helper.NFMap"%>
<jsp:useBean id="c" scope="session" class="nftrainer.Controller"/>
<%
String sLst;
List<NFMap> lstKV;
List<String> lst;
NFMap map;
boolean bool = false, solution;

String sTaskType = request.getParameter( "tasktype" );
if( sTaskType != null ) {
	if( sTaskType.equals("kv") ) {
		Enumeration parameterList = request.getParameterNames();
		lstKV = new ArrayList<NFMap>();
		while( parameterList.hasMoreElements() ) {
			String sName = parameterList.nextElement().toString();
			if(sName.matches("lst[0-9]*")) {
				sLst = request.getParameter( sName );
				String [] aLst = sLst.split(":");
				if (aLst != null) {
					map = new NFMap();
					if (aLst.length > 0) {
						for (String s : aLst[0].split(",")) {
							map.addToKeys(s);
							map.addToAll(s);
						}
					}
					if (aLst.length > 1) {
					  	for (String s : aLst[1].split(",")) {
					   		map.addToValues(s);
					    	map.addToAll(s);
					  	}
					}
	//			  	out.println( map.getKeys().toString() + ":" + map.getValues().toString() + "<br />");
				  	lstKV.add(map);
				}			
			}
		}
	//	out.println("Nutzereingabe: "+ lstKV +"<br />");
	//	out.println(c.compareUserSolution(lstKV) + "<br /><br />");
		out.println(c.compareUserSolution(lstKV));
	} else if( sTaskType.equals("lst") ) {
		sLst = request.getParameter( "lst" );
		lst = new ArrayList<String>();
		if (sLst != null) {
			for (String s : sLst.split(",")) {
				//out.println( s.toString() + "<br />");
				lst.add(s);
			}
		}
	//	out.println("Nutzereingabe: "+lst+"<br />");
	//	out.println(c.compareUserSolution(lst)+"<br /><br />");
		out.println(c.compareUserSolution(lst));
	} else if (sTaskType.equals("bool")) {
		if (request.getParameter("bool") != null && !"".equals(request.getParameter("bool"))) {
			bool = Boolean.parseBoolean(request.getParameter("bool"));
		}
		out.println(c.compareUserSolution(bool));
	} else {
		out.println("false");
	}
} else {
	out.println("false");
}
%>